//package com.ahcloud.enhance.justlock.configuration;
//
//import com.ahcloud.enhance.curator.configuration.CuratorConfiguration;
//import com.ahcloud.enhance.curator.configuration.CuratorProperties;
//import com.ahcloud.enhance.curator.configuration.RetryPolicyFactory;
//import com.ahcloud.enhance.curator.exception.ZkClientStartException;
//import com.ahcloud.enhance.curator.lock.ZkLock;
//import com.ahcloud.enhance.lock.base.LockUtils;
//import com.ahcloud.enhance.redisson.configuration.RedissonAutoConfigurationCustomizer;
//import com.ahcloud.enhance.redisson.configuration.RedissonProperties;
//import com.ahcloud.enhance.redisson.lock.RedissonILock;
//import com.google.common.base.Throwables;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.curator.framework.CuratorFramework;
//import org.apache.curator.framework.CuratorFrameworkFactory;
//import org.redisson.Redisson;
//import org.redisson.api.RedissonClient;
//import org.redisson.config.Config;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.boot.context.properties.EnableConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.io.IOException;
//import java.util.List;
//
///**
// * @program: distributedlock-enhance
// * @description:
// * @author: YuKai Fan
// * @create: 2024/4/30 23:05
// **/
//@Slf4j
//@Configuration
//@EnableConfigurationProperties(value = {RedissonProperties.class, CuratorConfiguration.class})
//public class JustLockConfiguration {
//
//    private final List<RedissonAutoConfigurationCustomizer> customizers;
//
//    @Autowired(required = false)
//    public JustLockConfiguration(List<RedissonAutoConfigurationCustomizer> customizers) {
//        this.customizers = customizers;
//    }
//
//    @Bean(destroyMethod = "close")
//    @ConditionalOnProperty(prefix = "distributed.lock", name = "type", havingValue = "zk")
//    public CuratorFramework curatorFramework(CuratorProperties properties) {
//        try {
//            CuratorFramework client = CuratorFrameworkFactory.newClient(
//                    properties.getZkUrls(),
//                    properties.getSessionTimeoutMs().intValue(),
//                    properties.getConnectionTimeoutMs().intValue(),
//                    RetryPolicyFactory.getPolicyByName(properties.getRetryPolicyConfig())
//            );
//            client.start();
//            log.info("Zookeeper Client [CuratorFramework] start succeed");
//            return client;
//        } catch (Exception e) {
//            log.error("Zookeeper Client [CuratorFramework] start failed, reason is {}", Throwables.getStackTraceAsString(e));
//            throw new ZkClientStartException("Zookeeper Client [CuratorFramework] start failed");
//        }
//    }
//
//    @Bean(destroyMethod = "shutdown")
//    @ConditionalOnProperty(prefix = "distributed.lock", name = "type", havingValue = "redisson", matchIfMissing = true)
//    public RedissonClient redisson(RedissonProperties properties) throws IOException {
//        Config config;
//        try {
//            config = Config.fromYAML(properties.getConfig());
//        } catch (IOException e) {
//            throw new IllegalArgumentException("Can't parse config", e);
//        }
//        if (customizers != null) {
//            for (RedissonAutoConfigurationCustomizer customizer : customizers) {
//                customizer.customize(config);
//            }
//        }
//        return Redisson.create(config);
//    }
//
//}
